<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Chat</title>
</head>
<script src="jquery-3.6.4.min.js"></script>
<script src="net_utils.js"></script>
<body>

开始聊天(按下ctrl+enter键发送)</br>

<textarea id="input" style="width: 85%;" rows="3" >阐述一下AIGC的概念</textarea><br/>
<button onclick="doChat()" >发送</button>
<hr/>
<div id="response"></div>
<script>
$("#input").keyup(function(e){
    //触发事件“ctrl+enter”键
    if (e.ctrlKey && e.which == 13){
        console.log("按下ctrl+enter键");
        doChat()
    }
});

function add_rsp(data,msg)
{
    var text = data;
    text = text.replace('\n','<br/>')
    $("#response").html($("#response").html()+ text)

}
function onChat(data,msg,status){
   // alert(data)
    console.log("data:["+data+"]")

    add_rsp(data,msg)
}

serverurl = 'http://139.9.144.238:10969/chatstream/'

function doChat(){
    //var url = "/chat/"
    //var url = "/stream/"
    var url=serverurl
    var msg = $("#input").val().trim();
    $("#input").focus();
    if (msg.length ==0 )return;
    var fullurl = url+msg
    //alert(fullurl)
    add_rsp('<hr/><span style="color: blue;">Q: '+msg+"</span> <br/>A: ");
    doGetStream(fullurl,onChat,msg)
    $("#input").val("")
}

</script>
</body>
</html>